package com.example.controller;


import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/api/chart")
@CrossOrigin
public class ChartController {

    @GetMapping("/monthly-sales")
    public Map<String, Object> getMonthlySales() {
        Map<String, Object> result = new HashMap<>();

        // X轴数据 - 月份
        result.put("months", Arrays.asList("1月", "2月", "3月", "4月", "5月", "6月",
                "7月", "8月", "9月", "10月", "11月", "12月"));

        // 系列数据
        Map<String, Object> series2023 = new HashMap<>();
        series2023.put("name", "2023年");
        series2023.put("data", Arrays.asList(120, 132, 101, 134, 90, 230, 210, 182, 191, 234, 290, 330));
        series2023.put("color", "#5470C6");

        Map<String, Object> series2024 = new HashMap<>();
        series2024.put("name", "2024年");
        series2024.put("data", Arrays.asList(150, 142, 121, 154, 110, 250, 230, 202, 211, 254, 310, 350));
        series2024.put("color", "#91CC75");

        result.put("series", Arrays.asList(series2023, series2024));

        return result;
    }

    @GetMapping("/user-growth")
    public Map<String, Object> getUserGrowth() {
        Map<String, Object> result = new HashMap<>();

        result.put("days", Arrays.asList("周一", "周二", "周三", "周四", "周五", "周六", "周日"));

        Map<String, Object> newUsers = new HashMap<>();
        newUsers.put("name", "新增用户");
        newUsers.put("data", Arrays.asList(120, 132, 101, 134, 90, 230, 210));
        newUsers.put("color", "#EE6666");

        Map<String, Object> activeUsers = new HashMap<>();
        activeUsers.put("name", "活跃用户");
        activeUsers.put("data", Arrays.asList(220, 182, 191, 234, 290, 330, 310));
        activeUsers.put("color", "#3BA272");

        result.put("series", Arrays.asList(newUsers, activeUsers));

        return result;
    }

    @GetMapping("/product-sales")
    public List<Map<String, Object>> getProductSales() {
        List<Map<String, Object>> productList = new ArrayList<>();

        Map<String, Object> productA = new HashMap<>();
        productA.put("name", "产品A");
        productA.put("value", 1048);
        productA.put("color", "#5470C6");
        productList.add(productA);

        Map<String, Object> productB = new HashMap<>();
        productB.put("name", "产品B");
        productB.put("value", 735);
        productB.put("color", "#91CC75");
        productList.add(productB);

        Map<String, Object> productC = new HashMap<>();
        productC.put("name", "产品C");
        productC.put("value", 580);
        productC.put("color", "#FAC858");
        productList.add(productC);

        Map<String, Object> productD = new HashMap<>();
        productD.put("name", "产品D");
        productD.put("value", 484);
        productD.put("color", "#EE6666");
        productList.add(productD);

        Map<String, Object> productE = new HashMap<>();
        productE.put("name", "产品E");
        productE.put("value", 300);
        productE.put("color", "#73C0DE");
        productList.add(productE);

        return productList;
    }
}